package com.graduation.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.graduation.springbootinit.model.entity.ShopPart.PlatformMonthlyIncome;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface PlatformMonthlyIncomeMapper extends BaseMapper<PlatformMonthlyIncome> {
    
    /**
     * 获取指定年月的平台收入数据
     */
    @Select("SELECT * FROM shop_part_platform_monthly_income WHERE year = #{year} AND LPAD(month, 2, '0') = LPAD(#{month}, 2, '0')")
    PlatformMonthlyIncome getMonthlyIncome(@Param("year") Integer year, @Param("month") Integer month);
    
    /**
     * 获取指定年份的所有月度收入数据
     */
    @Select("SELECT * FROM shop_part_platform_monthly_income WHERE year = #{year} ORDER BY month ASC")
    List<PlatformMonthlyIncome> getYearlyIncome(@Param("year") Integer year);
    
    /**
     * 获取指定年月的总佣金收入
     */
    @Select("SELECT SUM(commission_amount) FROM shop_part_monthly_store_sales WHERE year = #{year} AND LPAD(month, 2, '0') = LPAD(#{month}, 2, '0')")
    BigDecimal calculateTotalCommission(@Param("year") Integer year, @Param("month") Integer month);
    
    /**
     * 获取指定年月的活跃商铺数
     */
    @Select("SELECT COUNT(DISTINCT store_id) FROM shop_part_monthly_store_sales WHERE year = #{year} AND LPAD(month, 2, '0') = LPAD(#{month}, 2, '0') AND total_sales > 0")
    Integer countActiveStores(@Param("year") Integer year, @Param("month") Integer month);
}